const fs = require('fs');
const http = require('http');
const s2o = require('./s2o');
// const users = require('./users.json');

// console.log(Object.prototype.toString.call(users));
const server = http.createServer((req,res)=>{
    res.setHeader('content-type','text/html;charset=utf-8');
    // console.log(req.url);
    if(req.url!=='/favicon.ico') {
        // let req1 = req.toString();
        // console.log(users);
        let {username,pwd} = s2o(req.url)
        const data = JSON.stringify({username,pwd});
        console.log(data);
        // console.log(Object.prototype.toString.call(data));  // String  {"username":"zhangsan","pwd":"1234"}

        let str = s2o(req.url);
        let newStr = querystring.parse(str);
        console.log(s2o(req.url).toString());

        fs.appendFile('./users.json',arr,err=>{
            if(err) {
                return console.log(err);
                
            }
            console.log('写入成功');
        })
        users[users.length] = data;
        
    }
       
        res.end();

       
    
   
})
server.listen(8989);